package com.wanxi.step07test.controller;


import com.wanxi.step07test.dto.ResultDTO;
import com.wanxi.step07test.model.CompanyModel;
import com.wanxi.step07test.service.impl.CompanyServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//@Controller
@CrossOrigin
@RestController
@Api(tags = "公司管理",value = "公司Open api 入口")
public class CompanyController {
    @Autowired
    private CompanyServiceImpl companyService;

    @PreAuthorize("hasAuthority('company:findAll')")
    @RequestMapping("/back/company/findAll")
    @ApiOperation(value = "查询所有公司",response = ResultDTO.class,httpMethod = "GET")
//    @ResponseBody
    public ResultDTO findAll(CompanyModel company) {
        ResultDTO resultDTO = companyService.findAll(company);
        return resultDTO;
    }


    @PreAuthorize("hasAuthority('company:add')")
    @RequestMapping("/back/company/add")
    @ApiOperation(value = "新增公司",response = ResultDTO.class,httpMethod = "POST")
//    @ResponseBody
    public ResultDTO add(CompanyModel company) {

        ResultDTO resultDTO = companyService.add(company);
        return resultDTO;
    }

    @PreAuthorize("hasAuthority('company:delete')")
    @RequestMapping("/back/company/delete")
    @ApiOperation(value = "删除公司",response = ResultDTO.class,httpMethod = "POST")
//    @ResponseBody
    public ResultDTO delete(CompanyModel company) {

        ResultDTO resultDTO = companyService.delete(company);
        return resultDTO;
    }

    @PreAuthorize("hasAuthority('company:findById')")
    @RequestMapping("/back/company/findById")
    @ApiOperation(value = "查询公司",response = ResultDTO.class,httpMethod = "GET")
//    @ResponseBody
    public ResultDTO findById(CompanyModel company) {
        ResultDTO resultDTO = companyService.findById(company);
        return resultDTO;
    }

    @PreAuthorize("hasAuthority('company:update')")
    @RequestMapping("/back/company/update")
    @ApiOperation(value = "更新公司",response = ResultDTO.class,httpMethod = "POST")
//    @ResponseBody
    public ResultDTO update(CompanyModel company) {
        ResultDTO resultDTO = companyService.update(company);
        return resultDTO;
    }


}
